package com.thysdy.flowable.vo;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.thysdy.flowable.enums.CodeEnum;
import com.thysdy.flowable.exception.MyException;
import lombok.Data;

@Data
public class PageReturnVo<T> extends ReturnVo<T> {
    private Long totalCount;
    private Long pageNumber;
    private Long pageSize;
    private Long pageTotal;

    public PageReturnVo() {
    }

    public PageReturnVo(Long pageNumber, Long pageSize, Long pageTotal, Long totalCount, T data, CodeEnum codeEnum) {
        super(codeEnum,data);
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.pageTotal = pageTotal;
    }

    public PageReturnVo(CodeEnum codeEnum) {
        super(codeEnum);
    }

    public PageReturnVo(CodeEnum codeEnum, T data) {
        super(codeEnum, data);
    }

    public static PageReturnVo success() {
        return new PageReturnVo(CodeEnum.success);
    }

    public static <T> PageReturnVo success(T data) {
        return new PageReturnVo(CodeEnum.success, data);
    }
    public static <T> PageReturnVo<T> success(IPage<T> page) {
        PageReturnVo<T> pageReturnVo = new PageReturnVo(page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(),page.getRecords(),CodeEnum.success);
        return pageReturnVo;
    }
    public static <T> PageReturnVo successPage(Long pageNumber, Long pageSize, Long pageTotal, Long totalCount, T data) {
        PageReturnVo pageReturnVo = new PageReturnVo(pageNumber, pageSize, pageTotal, totalCount,data,CodeEnum.success);
        pageReturnVo.setCodeEnum(CodeEnum.success);
        return pageReturnVo;
    }

    public static <T> PageReturnVo exception(MyException e) {
        return new PageReturnVo(e.getCodeEnum());
    }

}
